// src/components/PrivateRoute.tsx

import React from 'react';
import Login from './login/Login';
import useAuth from '../components/AuthContext';
import { Navigate } from 'react-router-dom';

const PrivateRoute: React.FC<{ children: JSX.Element; allowedPermissions: string[] }> = ({
  children,
  allowedPermissions,
}) => {
    const route:any=window.location.href.split('/').pop()
    const token=localStorage.getItem('token')

    if (!token || !allowedPermissions.includes(route)) {
      return <Navigate to="/login" replace />;
    }
    return children;
};

export default PrivateRoute;